package org.geekbang.bigdata.flow;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowCountReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

    @Override
    protected void reduce(Text k3, Iterable<FlowBean> v3, Context context) throws IOException, InterruptedException {
        long sumDownFlow = 0L;
        long sumUpFlow = 0L;
        for (FlowBean v : v3) {
            sumDownFlow += v.getDownFlow();
            sumUpFlow += v.getUpFlow();
        }

        context.write(k3, new FlowBean(sumUpFlow, sumDownFlow));
    }
}
